import Axios from '@/utils/Axios'

// 获取任务列表
export interface TaskStatus {
    id: number;
    title: string;
    description: string;
    taskfile?: string;
    file?: string;
    status: number;
    createdAt: string;
    updatedAt: string;
}

export interface TaskListResponse {
    tasks: TaskStatus[];
    total_count: number;
    page: number;
    total_pages: number;
}

export function getTaskList(params: {
    user_id?: string;
    page?: number;
    limit?: number;
    sort_by?: string;
    order?: string;
    status?: number;
}): Promise<TaskListResponse> {
    return Axios.get("/backapi/tasks", {params});
}
// 获取任务详情
export function getTaskDetail(taskId: number): Promise<any> {
  return Axios.get(`/backapi/tasks/${taskId}`);
}

// 下载任务文件
export function downloadTaskFile(taskId: number): Promise<any> {
    return Axios.get("/backapi/tasks/{task_id}/files".replace('{task_id}', taskId.toString()), {
        responseType: "blob"
    });
}
export function uploadFile(taskId: number,params :any): Promise<any> {
    return Axios.post("/backapi/tasks/{task_id}/files".replace('{task_id}', taskId.toString()), params, {
        headers: {
            "Content-Type": "multipart/form-data"
        }
    });
}
